<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class UserInfo extends Model
{
	protected $table = 'user_infos';

    public $fillable = [
    	'user_id',
    	'name',
    	'head_img',
    	'birthday',
    	'nickname',
    	'address',
    	'phone',
    	'email',
    	'sex',
    ];

    public $primaryKey = 'user_id';

    public $timestamps = false;

    public function wxUser(){
        return $this->belongsTo('App\Models\WxUser', 'user_id', 'user_id');
    }

    protected $appends = [
        'sex_description',
    ];

    const SEX_MALE = 1;
    const SEX_FEMALE = 2;

    public static $_SEX_DESCRIPTION = [
        self::SEX_FEMALE => '女',
        self::SEX_MALE => '男',
        0 => '未知',
    ];

    public function getSexDescriptionAttribute($value)
    {
        if(array_key_exists('sex', $this->attributes))
        {
            return self::$_SEX_DESCRIPTION[$this->attributes['sex']];
        }
    }

}
